﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CatchMeGame
{
    public partial class CatchForm : Form
    {
        Random random = new Random();
        
        public CatchForm()
        {
            InitializeComponent();
        }


        private void buttonCatchMe_MouseEnter(object sender, EventArgs e)
        {
            bool good = false;
            int move = 30;
            while (good == false && move>0)
            {
                move--;
                int position = random.Next(4);
                switch (position)
                {
                        
                    case 0:
                        if (buttonCatchMe.Location.X + buttonCatchMe.Size.Width < buttonCatchMe.Parent.Size.Width - 80)
                        {
                            buttonCatchMe.Location = new Point(buttonCatchMe.Location.X + buttonCatchMe.Size.Width, buttonCatchMe.Location.Y);
                            good = true;
                        }
                        break;
                    case 1:
                        if (buttonCatchMe.Location.X - buttonCatchMe.Size.Width > 0)
                        {
                            buttonCatchMe.Location = new Point(buttonCatchMe.Location.X - buttonCatchMe.Size.Width, buttonCatchMe.Location.Y);
                            good = true;
                        }
                        break;
                    case 2:
                        if (buttonCatchMe.Location.Y + buttonCatchMe.Size.Height < buttonCatchMe.Parent.Size.Height - 70)
                        {

                            buttonCatchMe.Location = new Point(buttonCatchMe.Location.X, buttonCatchMe.Location.Y + buttonCatchMe.Size.Height);
                            good = true;
                        }
                        break;
                    case 3:
                        if (buttonCatchMe.Location.Y - buttonCatchMe.Size.Height > 0)
                        {
                            buttonCatchMe.Location = new Point(buttonCatchMe.Location.X, buttonCatchMe.Location.Y - buttonCatchMe.Size.Height);
                            good = true;
                        }
                        break;
                }
            }
        }

        private void buttonCatchMe_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You catched me!");
        }
    }
}
